﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KongMing.ORM.EFCore
{
    internal class 连表查询
    {
        public static void JoinQuery()
        {
            using (var db = new EFDBContext())
            {
                var query_join_lambda = db.StoreBookStock
                    .Join(db.BookStore, sbs => sbs.BookStoreId, bs => bs.Id, 
                    (sbs, bs) => new { sbs, bs }).Select(x => new
                    {
                
                    }).DefaultIfEmpty().ToList();



                //左连接 需要用到GroupJoin() 和 SelectMany() 和 DefaultIfEmpty() 来实现左连接 
                var query_leftjoin = db.StoreBookStock
                    .GroupJoin(db.BookStore, x => x.BookId, y => y.Id, (x, y) => new { sbs = x, bs = y })
                    .SelectMany(xy => xy.bs.DefaultIfEmpty(), (x, y) => new { sbs = x.sbs, bs = y })
                    .Select(x => new { });
                
                //BookName = b.Title,
                //    Author = b.Author,
                //    InPrice = b.InPrice
                //var query_join_linq = from bs in db.BookStores
                //                      join b in db.Books
                //                      on bs
                //var a = (from c in db.Books
                //               select c.GetType().GetProperty(item.Value).GetValue(c, null)).Distinct().ToList();
            }
        }
    }
}
